package com.git.auto.login;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by wangquan on 2017/4/18.
 */
@Configuration
@EnableConfigurationProperties(LoginProperties.class)
@ConditionalOnProperty(prefix = "login", name = "enable", havingValue = "true")
public class LoginAutoConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    private LoginProperties loginProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addWebRequestInterceptor(new LoginInterceptor())
                .addPathPatterns(loginProperties.getUrlPatterns())
                .excludePathPatterns(loginProperties.getExcludedUrls());
        
    }

}